package com.example.Receiver;

import com.example.Config.RabbitMQConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description 消息接收器
 * @Author IT小辉同学
 * @Date 2023/06/16
 */
@Service
public class MessageReceiver {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * @param message 消息
     * @Description 处理消息
     * @Author IT小辉同学
     * @Date 2023/06/16
     */
    /**
     * 普遍
     */
//    @RabbitListener(queues = "simple.hello")
//    public void handleMessage(String message) {
//        System.out.println("我收到了你的祝福: " + message);
//    }
    /**
     * 这是广播
     * 存在多个消费者
     */
//    @RabbitListener(queues = "queue01")
////    public void receiver01(String message) {
////        System.out.println("队列01：奔赴山海，" + message);
////    }
////
////    /**
////     * @param message 消息
////     * @Description 消费者012
////     * @Author IT小辉同学
////     * @Date 2023/06/16
////     */
////    @RabbitListener(queues = "queue02")
////    public void receiver02(String message) {
////        System.out.println("队列02：向阳而生，" + message);
////    }

    /**
     * 订阅模式、发布模式
     */

//    /**
//     * @param message 消息
//     * @Description 消费者01
//     * @Author IT小辉同学
//     * @Date 2023/06/16
//     */
//    @RabbitListener(queues = "queue01")
//    public void receiver01(String message) {
//        System.out.println("队列01——路由01：奔赴山海，" + message);
//    }
//
//    /**
//     * @param message 消息
//     * @Description 消费者012
//     * @Author IT小辉同学
//     * @Date 2023/06/16
//     */
//    @RabbitListener(queues = "queue02")
//    public void receiver02(String message) {
//        System.out.println("队列02——路由02：向阳而生，" + message);
//    }
    /**
     * 路由模式
     */
//    @RabbitListener(queues = RabbitMQConfig.QUEUE_NAME_1)
//    public void receiveFromQueue1(String message) {
//        System.out.println("Received message from queue 1: " + message);
//    }
//
//    @RabbitListener(queues = RabbitMQConfig.QUEUE_NAME_2)
//    public void receiveFromQueue2(String message) {
//        System.out.println("Received message from queue 2: " + message);
//    }
/**
 * 主题模式
 */

@RabbitListener(queues = RabbitMQConfig.QUEUE_NAME_1)
public void receiveFromQueue1(String message) {
    System.out.println("Received message from queue 1: " + message);
}

    @RabbitListener(queues = RabbitMQConfig.QUEUE_NAME_2)
    public void receiveFromQueue2(String message) {
        System.out.println("Received message from queue 2: " + message);
    }

    @RabbitListener(queues = RabbitMQConfig.QUEUE_NAME_3)
    public void receiveFromQueue3(String message) {
        System.out.println("Received message from queue 3: " + message);
    }

}




